// subPackages/packageA/secondaryDebtorClue/secondaryDebtorClue.ts
import { getDwListApi, getDwYearCountListApi } from "../../api/shesu"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    page: 1,
    perPage: 10,
    total: 0,
    debtorId: "",
    searchInputClass: "",
    placeholderText: "搜索...",
    keyWords: "",
    searchDisabled: true,
    clearable: false,
    contentList: [],
    staYearValue: "", //立案年份
    staYear: {
      options: [
        {
          label: "全部",
          value: "",
        }
      ]
    },
    staStatusValue: "",
    staStatus: {
      options: [
        {
          value: '',
          label: '全部'
        },
        {
          value: 0,
          label: '有效',
        },
        {
          value: 1,
          label: '无效',
        }
      ]
    },
    staWritValue: "",
    staWrit: {
      options: [
        {
          value: '',
          label: '全部'
        },
        {
          value: '1',
          label: '有',
        },
        {
          value: '0',
          label: '无',
        }
      ]
    },
  },
  // search-bar 搜索栏
  onChange(e: any) {
    const id = e.currentTarget.id
    const value = e.detail.value
    if (id === '1') {
      this.setData({
        "staYearValue": value
      });
    }
    if (id === '2') {
      this.setData({
        "staStatusValue": value
      });
    }
    if (id === '3') {
      this.setData({
        "staWritValue": value
      });
    }
    this.searchHandle();
  },
  // 点击展开搜索
  searchFocus() {
    this.setData({
      searchInputClass: "input-is-focus",
      placeholderText: this.data.keyWords || "输入企业名称，次债务人，案号，经办法院"
    }, () => {
      this.setData({
        searchDisabled: false,
        clearable: true
      })
    })
  },
  // 确认搜索
  searchBlur() {
    this.searchHandle();
  },
  // 收起
  searchFold() {
    this.setData({
      searchInputClass: "",
      placeholderText: "搜索...",
      searchDisabled: true,
      clearable: false
    })
  },
  // 获取年份列表
  getDwYearList() {
    let para = {
      id: this.data.debtorId
    }
    getDwYearCountListApi(para).then((res: any) => {
      if (res.code === '000') {
        let contentList = res.content;
        contentList.forEach((item: any) => {
          item.label = item.name + `（${item.value}）`;
          item.value = item.name;
        });
        contentList.unshift({
          label: "全部",
          value: "",
        })
        this.setData({
          "staYear.options": contentList || []
        })
      }

    })
  },
  searchHandle() {
    this.data.page = 1;
    this.setData({
      contentList: []
    })
    this.getList();
  },
  // 获取线索列表
  getList() {
    let para = {
      page: this.data.page,
      perPage: this.data.perPage,
      id: this.data.debtorId,
      bcClueStatus: this.data.staStatusValue,
      query: this.data.keyWords,
      yearInfo: this.data.staYearValue
    }
    if (this.data.staWritValue) {
      para.wxStatus = this.data.staWritValue;
    }
    this.setData({
      loading: true
    })
    getDwListApi(para).then((res: any) => {
      if (res.code === '000') {
        let content = res.content;
        this.setData({
          total: content.total,
          contentList: this.data.contentList.concat(content.list || []),
          loading: false
        })
      }
    })
  },

  // 上拉到底
  scrolltolower() {
    if (this.data.total > this.data.contentList.length) {
      this.data.page++;
      this.getList();
    }
  },
  // 下拉刷新
  refresherrefresh() {
    this.searchHandle();
  },
  // 查看次债务人详情
  viewDetail(e: any) {
    let id = e.currentTarget.dataset.id;
    console.log(id, "id")
    wx.navigateTo({
      url: "/subPackages/packageA/shesu/secondDebtorDetail/secondDebtorDetail?id=" + id
    })
  },
  // 查看文书
  checkWs(e: any) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/subPackages/packageA/writDetail/writDetail?id=" + id + "&type=abc"
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(option) {
    this.data.debtorId = option.debtorId;
    this.getDwYearList()
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },


})